package com.beinhospital_sw21_h2_05.beinhospitalsw21h205.mapper;

import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.Admission;
import com.beinhospital_sw21_h2_05.beinhospitalsw21h205.entity.MedicalOrder;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * MyBatis Mapper接口，用于与数据库表Patient进行交互
 */
@Mapper
public interface PatientMapper {

    /**
     * 根据Flag和PatientID查询Admission信息列表
     * @param flag 病人状态
     * @param patientID 病人ID
     * @return Admission信息列表
     */
    List<Admission> list(Integer flag, Integer patientID);

    /**
     * 根据UserID获取PatientID
     * @param userID 用户ID
     * @return PatientID
     */
    @Select("select PatientID from Patient where UserID = #{userID}")
    Integer getPatientID(Integer userID);

    /**
     * 根据科室名获取科室ID
     * @param departmentName 科室名
     * @return 科室ID
     */
    @Select("select DepartmentID from Department where DepartmentName = #{departmentName}")
    int getDepartmenID(String departmentName);

    /**
     * 添加新的Admission信息
     * @param admission Admission对象
     */
    @Insert("insert into Admission(admission_date, DepartmentID, bed_number, PatientID, Flag, PatientName, DepartmentName) values(#{admission_date}, #{DepartmentID}, #{bed_number}, #{PatientID}, #{Flag}, #{PatientName}, #{DepartmentName})")
    void add(Admission admission);

    /**
     * 根据PatientID查询病人的医嘱信息列表
     * @param patientID 病人ID
     * @return 医嘱信息列表
     */
    @Select("select * from MedicalOrder where PatientID = #{patientID}")
    List<MedicalOrder> list1(Integer patientID);
}
